<template>
  <div class="page-main">
    <CustomForm
      :formInline="form"
      @onSubmit="onSubmit"
      @resetTable="resetTable"
      :labelWidth="`120px`"
    >
      <el-form-item label="公司名称">
        <el-input v-model="form.business_name" placeholder="输入公司名称"></el-input>
      </el-form-item>
      <el-form-item label="道路运输许可证" style="margin-left: 20px;">
        <el-input v-model="form.business_license" placeholder="输入道路运输许可证号"></el-input>
      </el-form-item>
      <el-form-item label="许可证号状态" style="margin-left: 20px;">
        <el-select v-model="form.type" placeholder="许可证号状态" @change="changeType">
          <el-option :label="`全部`" :value="`-1`"></el-option>
          <el-option :label="`有`" :value="`1`"></el-option>
          <el-option :label="`无`" :value="`0`"></el-option>
        </el-select>
      </el-form-item>
    </CustomForm>
    <!-- <el-button type="primary" @click="addGoodsEvt" style="margin-bottom: 5px;">添加货物</el-button> -->
    <CustomDescriptions :data="descriptionsData" :styleBox="{}"></CustomDescriptions>
    <el-table
      :data="list"
      style="width: 100%"
      height="620"
      v-loading="tableloading"
      border
      ref="multipleTable"
    >
      <el-table-column prop="id" label="ID" align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column
        prop="business_name"
        label="公司名称"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        prop="business_license"
        label="道路运输许可证"
        align="center"
        :show-overflow-tooltip="true"
      >
        <template
          slot-scope="scope"
        >{{scope.row.business_license ? scope.row.business_license : '--' }}</template>
      </el-table-column>
      <el-table-column
        prop="credit_code"
        label="社会信用代码"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column prop="add_time" label="添加时间" align="center" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="edit(scope.row)">编辑</el-button>
          <el-button v-if="false" type="danger" size="mini" @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="form.page"
      :page-sizes="$pageSizeList"
      :page-size="form.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    ></el-pagination>

    <el-dialog
      class="dataDialog"
      title="编辑公司"
      :visible.sync="editDialog"
      width="30%"
      top="10vh"
      :close-on-click-modal="false"
    >
      <EditTransport v-if="editDialog" :row="editRow" @refresh="editDialog = false,initial()" />
    </el-dialog>
  </div>
</template>

<script>
import { getTransportCompany, deleteTransportCompany } from "@/api/set";
import EditTransport from "./components/editTransport.vue";
export default {
  name: "transportManage",
  components: {
    EditTransport
  },
  data() {
    return {
      form: {
        business_name: "",
        business_license: "",
        type: '-1', // 1：有 0:没有
        page: 1,
        pageSize: 10
      },
      goodTypeList: [],
      list: [],
      total: 0,
      tableloading: false,
      editDialog: false,
      editRow: {},
      descriptionsData: [
        {
          label: "运输公司总数",
          count: 0,
          unit: "(家)"
        },
        {
          label: "有效运输许可证数",
          count: 0,
          unit: "(家)"
        }
      ]
    };
  },
  mounted() {
    this.initial();
  },
  methods: {
    async initial() {
      this.tableloading = true;
      let result = await getTransportCompany(this.form);
      console.log("result", result);
      this.tableloading = false;

      if (result.code == 200) {
        this.list = result.data.data ? result.data.data : [];
        this.total = result.data.total ? result.data.total : 0;
        this.descriptionsData[0].count = result.data.total;
        this.descriptionsData[1].count = result.extra.number;
      }
    },
    resetTable() {
      this.form = {
        business_name: "",
        business_license: "",
        type:'-1',
        page: 1,
        pageSize: 10
      };
      this.initial();
    },
    handleSizeChange(pageSize) {
      this.form.pageSize = pageSize;
      this.initial();
    },
    handleCurrentChange(page) {
      this.form.page = page;
      this.initial();
    },
    addGoodsEvt() {
      this.addGoodsDialog = true;
    },
    edit(row) {
      this.editRow = row;
      this.editDialog = true;
    },
    del(row) {
      this.$confirm(`确定要删除该公司吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async () => {
          let result = await deleteTransportCompany({
            id: row.id
          });
          if (result.code == 200) {
            this.$message.success(result.msg || "删除成功");
            this.initial();
          }
        })
        .catch(() => {});
    },
    changeGoodsType() {
      this.form.page = 1;
      this.initial();
    },
    onSubmit() {
      this.form.page = 1;
      this.initial();
    },
    changeType(val){
      console.log('val',val);
      this.initial();
      
    }
  }
};
</script>

<style lang="scss" scoped>
.transportManage {
}
</style>
